package com.jlu155.CourseManager.service;

import com.jlu155.CourseManager.Bean.PageRequest;
import com.jlu155.CourseManager.Bean.PageResult;

import com.jlu155.CourseManager.entity.Teacher;
import com.jlu155.CourseManager.repository.CollegeRepository;
import com.jlu155.CourseManager.repository.TeacherRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherService {


    @Autowired
    private TeacherRepository teacherRepository;
    @Autowired
    private CollegeRepository collegeRepository;
    public PageResult<Teacher> getTeacherPage(PageRequest pageRequest){
        PageResult<Teacher> pageResult=new PageResult<Teacher>();
        List<Teacher> teachers;

            teachers=teacherRepository.findTeacherByCond(pageRequest.getName(),pageRequest.getTid(),pageRequest.getCollege_id());

        pageResult.setPageList(teachers);
        pageResult.setPageNumber(teachers.size());
        pageResult.cutPage(pageRequest.getIndex(),pageRequest.getSize());
        for(Teacher t: pageResult.getPageList()){
            t.setCollege(collegeRepository.findCollegeById(t.getCollege_id()));
        }
        return pageResult;
    }


        public boolean loginValidate(Integer tid,String password){
                if(password.equals(teacherRepository.getTeacherPasswdById(tid))){
                        return true;
                }
                return false;
        }



}
